package com.gonsin.i18n.logic.utils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


/**
 * 忽略大小写的ConcurrentHashMap
 */
public class IgnoreCaseConcurrentHashMap<K,V> extends ConcurrentHashMap<K,V> {

    public IgnoreCaseConcurrentHashMap() {
        super();
    }

    public IgnoreCaseConcurrentHashMap(Map<? extends K, ? extends V> m) {
        super(m);
    }

    @Override
    public V put(K key, V value) {
        if(key instanceof String){
            key = (K) ((String) key).toLowerCase();
        }
        return super.put(key, value);
    }

    @Override
    public V get(Object key) {
        if(key instanceof String){
            key = ((String) key).toLowerCase();
        }
        return super.get(key);
    }

    @Override
    public void putAll(Map<? extends K, ? extends V> m) {
        m.forEach(this::put);
    }
}
